<!DOCTYPE html>
<html lang="en">
	<head>
	
    <title>CBE PMP Toolkit - Wireless System sMAP Source Setup</title>

    <link href="bootstrap.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="plot.css"/>
    <style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
      .sidebar-nav {
        padding: 9px 0;
      }
    </style>
    <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="Math.uuid.js"></script>
    <script type="text/javascript" src="bootstrap.min.js"></script>
    <script type="text/javascript" src="pinger.js"></script>
    <script>
	    $(document).ready(function(){
			$("form#configForm").submit(function(){
				createConfigFile(true);
				return false;
			});
			$("input#default_config").click(function() {
				$.post("sMAPloadConfig.php", {"username":"default"}, function(data){
					//console.log(data);					
					var fields = $.parseJSON(data);
					$('textarea#units').val(fields["units"]);
					$('textarea#calibrations').val(fields["calibrations"]);
				});
			});
			$("input#loadSaved").click(function() {
				var username = $('input#username').val();
				$.post("sMAPloadConfig.php", {"username":username}, function(data){
					//console.log(data);					
					var fields = $.parseJSON(data);
					$('select#timezone').val(fields["timezone"]);
					$('textarea#units').val(fields["units"]);
					$('textarea#calibrations').val(fields["calibrations"]);
					$('input#uuid').val(fields["uuid"]);
					createConfigFile(false);
				});
			});
			$("input#startSource").click(function() {
				$.ajax({
				   type: "POST",
				   url: "/cgi-bin/startSmapSource.cgi",
				   success: function() {
				       $('#success').html("<strong>&nbsp;&nbsp;sMAP source started</strong>").fadeIn().delay(2000).fadeOut(1000);
				   }
				});
			});
			$("input#stopSource").click(function() {
				$.ajax({
				   type: "POST",
				   url: "/cgi-bin/stopSmapSource.cgi",
				   success: function() {
				       $('#success').html("<strong>&nbsp;&nbsp;sMAP source stopped</strong>").fadeIn().delay(2000).fadeOut(1000);
				   }
				});
			});
			$("input#restartSource").click(function() {
				$.ajax({
				   type: "POST",
				   url: "/cgi-bin/stopSmapSource.cgi",
				   success: setTimeout(function() {
					   $.ajax({
						   type: "POST",
						   url: "/cgi-bin/startSmapSource.cgi",
						   success: function() {
						       $('#success').html("<strong>&nbsp;&nbsp;sMAP source restarted</strong>").fadeIn().delay(2000).fadeOut(1000);
						   }
						});    
				   },2000)
				});
			});
			$("input#shutdownPC").click(function() {
				$.ajax({
				   type: "POST",
				   url: "/cgi-bin/shutdownPC.cgi",
				   success: function() {
				       $('#success2').html("<strong>&nbsp;&nbsp;Manager PC shutting down now</strong>").fadeIn().delay(2000).fadeOut(1000);
				   }
				});
			});
			$("input#restartPC").click(function() {
				$.ajax({
				   type: "POST",
				   url: "/cgi-bin/restartPC.cgi",
				   success: function() {
				       $('#success2').html("<strong>&nbsp;&nbsp;Manager PC restarting now</strong>").fadeIn().delay(2000).fadeOut(1000);
				   }
				});
			});
		});
		function createConfigFile(save){
			var username = $('input#username').val();
			var uuid = $('input#uuid').val();
			var units = $('textarea#units').val();
			var timezone = $('select#timezone').val();
			var calibrations = $('textarea#calibrations').val();
			$.ajax({
				type: "POST",
				url: "sMAPconfig.php",
				data: {"username":username, 
					"uuid":uuid,
					"units": units,
					"timezone": timezone,
					"calibrations": calibrations},
				success: function(msg){
					if (save){
					 $('#success').html("<strong>&nbsp;&nbsp;Saved successfully</strong>").fadeIn().delay(2000).fadeOut(1000);
					}
					}    
			})
		}
	</script>


  </head>

  <body>

    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container-fluid">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <img src="title_icon.png" class="brand" style="padding-right: 2px"/><a class="brand" style="padding-top: 10px" href="http://smap.cbe.berkeley.edu/pmp/">&nbsp;CBE BPE Toolkit</a>
          <div class="nav-collapse">
            <ul class="nav" style="padding-top: 1px">
              <li><a href="http://smap.cbe.berkeley.edu/pmp/">Home</a></li>
              <li><a href="http://smap.cbe.berkeley.edu/static/doc/_build/html/">Documentation</a></li>
            </ul>
      		<p class="navbar-text pull-right" style="color: white">
          </p>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>

    <div class="container-fluid">
      <div class="row-fluid">
        <div class="span2">
          <div class="well sidebar-nav">
           	<ul class="nav nav-list">
           	  <li class="nav-header" id="setupHeader">Setup</li>
           	  
              <li><a id="pmpsetup" href="http://cbevigilent.dyndns.org/pmpsetup/">sMAP Source</a></li>
              <li class="nav-header">Project Information</li>
              <li id="home"><a href="http://smap.cbe.berkeley.edu/pmp/home">Home</a></li>
              <li id="building"><a href="http://smap.cbe.berkeley.edu/pmp/building">Building</a></li>
              <li id="maps"><a href="http://smap.cbe.berkeley.edu/pmp/maps">Maps</a></li>
              <li id="zones"><a href="http://smap.cbe.berkeley.edu/pmp/zones/">Zones</a></li>
              <li id="sensors"><a href="http://smap.cbe.berkeley.edu/pmp/sensors/">Sensors</a></li>
              <li id="deviceInstance"><a href="http://smap.cbe.berkeley.edu/pmp/deviceInstance/">Devices</a></li>
              <li class="nav-header">Analysis</li>
              <li id="trending"><a href="http://smap.cbe.berkeley.edu/pmp/trending/">Trending</a></li>
              <!--<li><a href="#">Energy</a></li>
              <li><a href="#">Water</a></li>-->
              <li id="comfort"><a href="http://smap.cbe.berkeley.edu/pmp/comfort/">Thermal Comfort</a></li>
              <li id="lighting"><a href="http://smap.cbe.berkeley.edu/pmp/lighting/">Lighting</a></li>
              <li id='acoustics'><a href="http://smap.cbe.berkeley.edu/pmp/acoustics/">Acoustics</a></li>
              <li id='iaq'><a href="http://smap.cbe.berkeley.edu/pmp/iaq/">IAQ</a></li>
              <li class="nav-header">Reporting</li>
              <li id="scsetup"><a href="http://smap.cbe.berkeley.edu/pmp/scsetup/">Setup</a></li>
              <li id="scorecard"><a href="http://smap.cbe.berkeley.edu/pmp/scorecard/">Scorecard</a></li>
              <li id="report"><a href="http://smap.cbe.berkeley.edu/pmp/report/">Report</a></li>
            </ul>    
          </div><!--/.well -->
        </div><!--/span-->
        <div class="span10" id="mainContent">
			<form id="configForm" method="post" action="">
        		<p><h4>Global Setup</h4></p>
        		<div class='form-inline'>
	        		<div class="input-prepend">
	            		<span class="add-on">Project short name</span><input type="text" name="username" id="username" class="span2" />&nbsp;&nbsp;
	            		<input type="button" value="Load saved configuration" id="loadSaved" class="btn"/><br>
	            		<label class="help-inline">No spaces or special characters, e.g. nytimes</label>
	          		</div><br><br>
	          		<div class="input-prepend">
	            		<span class="add-on">Time zone</span>
						<select name="timezone" id="timezone">
							<option value="America/Boise" label="Boise">Boise</option>
							<option value="America/Chicago" label="Chicago">Chicago</option>
							<option value="America/Denver" label="Denver">Denver</option>
							<option value="America/Detroit" label="Detroit">Detroit</option>
							<option value="America/Indiana/Indianapolis" label="Indiana (Indianapolis)">Indiana (Indianapolis)</option>
							<option value="America/Indiana/Knox" label="Indiana (Knox)">Indiana (Knox)</option>
							<option value="America/Indiana/Marengo" label="Indiana (Marengo)">Indiana (Marengo)</option>
							<option value="America/Indiana/Petersburg" label="Indiana (Petersburg)">Indiana (Petersburg)</option>
							<option value="America/Indiana/Tell_City" label="Indiana (Tell City)">Indiana (Tell City)</option>
							<option value="America/Indiana/Vevay" label="Indiana (Vevay)">Indiana (Vevay)</option>
							<option value="America/Indiana/Vincennes" label="Indiana (Vincennes)">Indiana (Vincennes)</option>
							<option value="America/Indiana/Winamac" label="Indiana (Winamac)">Indiana (Winamac)</option>
							<option value="America/Indianapolis" label="Indianapolis">Indianapolis</option>
							<option value="America/Kentucky/Louisville" label="Kentucky (Louisville)">Kentucky (Louisville)</option>
							<option value="America/Kentucky/Monticello" label="Kentucky (Monticello)">Kentucky (Monticello)</option>
							<option value="America/Los_Angeles" label="Los Angeles">Los Angeles</option>
							<option value="America/Louisville" label="Louisville">Louisville</option>
							<option value="America/New_York" label="New York">New York</option>
							<option value="America/North_Dakota/Center" label="North Dakota (Center)">North Dakota (Center)</option>
							<option value="America/North_Dakota/New_Salem" label="North Dakota (New Salem)">North Dakota (New Salem)</option>
							<option value="America/Phoenix" label="Phoenix">Phoenix</option>
							<option value="America/Toronto" label="Toronto">Toronto</option>
							<option value="America/Vancouver" label="Vancouver">Vancouver</option>	
					</select>
	          		</div><br><br>
	          		<div class="input-prepend">
	            		<span class="add-on">UUID</span><input type="text" name="uuid" id="uuid" class="span4" />&nbsp;&nbsp;
	            		<input type="button" class="btn" value="Generate" onclick="generate_uuid();" />
	            		<script>
	            			function generate_uuid(){
	            				document.getElementById("uuid").value = Math.uuid();
	            			}
	            		</script>
	          		</div>
          		</div>
          		<p style="padding-top: 5px"><input type="button" class="btn" id="default_config" value="Load default units/calibrations" /></p>
        		<p><h4>Configure units</h4></p>
        		<textarea name="units" id="units" rows="10" class="span4"></textarea>
        		<p><h4>Configure calibrations</h4></p>
        		<textarea name="calibrations" id="calibrations" rows="10" class="span4"></textarea>	
			    <p><input type="submit" value="Save" class="btn"/><span id="success"></span></p>
			</form>
			<div>
				<input type="button" class="btn" id="startSource" value="Start sMAP source" />&nbsp;&nbsp;
				<input type="button" class="btn" id="stopSource" value="Stop sMAP source" />&nbsp;&nbsp;
				<input type="button" class="btn" id="restartSource" value="Restart sMAP source" />
			</div>
			<div style="margin-top: 10px">
				<p><h4>Manager PC controls</h4></p>
				<input type="button" class="btn" id="restartPC" value="Restart manager PC" />&nbsp;&nbsp;
				<input type="button" class="btn" id="shutdownPC" value="Shutdown manager PC" />&nbsp;&nbsp;
				<span id="success2"></span>
			</div>
			
        </div><!--/span-->
      </div><!--/row-->
      <hr>
<footer>
    <div>
    	<div style="float: left"><a href="http://cbe.berkeley.edu"><img src="cbeLogo90px.jpg"></a>&nbsp;&nbsp;</div>
    	<div class="bottom" style="float: left">
        	This work was funded by the CEC-PIER organization and the Center for the Built Environment. This project rests upon the shoulders of other open-source projects with special thanks to the folks at LoCal. This website has been tested on Chrome, Safari, Firefox, and Internet Explorer 9. The trending application is not compatible with Internet Explorer.<br>
     		<a href="http://cs.berkeley.edu/~stevedh/smap2/">sMAP</a> 
		    &nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
      		<a href="http://local.cs.berkeley.edu">LoCal</a>
      		&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
          	<a href="http://www.ama3.com/anytime/">Any+Time</a>
	      	&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
	      	<a href="http://jquery.com/">jQuery</a>
	      	&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
	      	<a href="http://jstree.com/">jsTree</a>
	      	&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
	      	<a href="http://code.google.com/p/flot/">Flot</a>
	      	&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
	      	<a href="http://www.highcharts.com/">Highcharts</a>
	      	&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
	      	<a href="http://twitter.github.com/bootstrap/index.html">Bootstrap</a>
	      	<br>
      </div>
    </div>
    <div style="float: right">
    	<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" /></a>
    </div>
</footer>

    </div><!--/.fluid-container-->



</body></html>
